package com.goldsprite.ruletilemap.examples;

import com.goldsprite.ruletilemap.core.MapRenderer;
import com.goldsprite.ruletilemap.core.RegularizationHandler;
import com.goldsprite.ruletilemap.core.RuleTile;

public class Demo {
    public static void main(String[] args) {
        // 初始化规则处理器
        RegularizationHandler handler = new RegularizationHandler();

        // 从配置类创建规则
        RuleTile grassRule = RuleConfig.createGrassRuleTile();
        handler.registerRuleTile(grassRule);

        // 初始化渲染器
        MapRenderer renderer = new MapRenderer();
        renderer.initializeDefaultIcons("g1 0 1 2 3 4 5 6 7 8 9 10", "? · ┏ ━ ┓ ┃ ▓ ┃ ┗ ━ ┛ ▒");

        System.out.println("=== 固定地图演示 ===");
        demonstrateFixedMap(handler, renderer);

        System.out.println("\n=== 随机地图演示 ===");
        demonstrateRandomMap(handler, renderer);
    }

    private static void demonstrateFixedMap(RegularizationHandler handler, MapRenderer renderer) {
        // 固定地图数据
        String mapData =
                        "0 g1 g1 g1 g1 0 0  g1 g1 0  0" + "\n" +
                        "0 g1 g1 g1 g1 0 0  g1 g1 0  0" + "\n" +
                        "0 g1 g1 0  g1 0 g1 g1 g1 g1 0" + "\n" +
                        "0 g1 g1 g1 g1 0 g1 g1 g1 g1 0" + "\n" +
                        "0 g1 g1 g1 g1 0 0  g1 g1 0  0";

        System.out.println("原始地图:");
        renderer.renderMap(mapData);

        System.out.println("\n规则化后地图:");
        String processedMap = handler.processMap(mapData);
        renderer.renderMap(processedMap);
    }

    private static void demonstrateRandomMap(RegularizationHandler handler, MapRenderer renderer) {
        // 创建随机地图 (15x8, 草地密度70%)
        String randomMap = RuleConfig.createRandomMap(30, 24, 0.8);

        System.out.println("随机生成地图:");
        renderer.renderMap(randomMap);

        System.out.println("\n规则化后地图:");
        String processedRandomMap = handler.processMap(randomMap);
        renderer.renderMap(processedRandomMap);

        // 可以多次演示不同的随机地图
        System.out.println("\n=== 另一个随机地图 ===");
        String anotherRandomMap = RuleConfig.createRandomMap(25, 18, 0.65);
        System.out.println("随机生成地图:");
        renderer.renderMap(anotherRandomMap);
        System.out.println("\n规则化后地图:");
        String processedAnotherMap = handler.processMap(anotherRandomMap);
        renderer.renderMap(processedAnotherMap);
    }
}
